package shuogg.codefix.filter;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * @description HttpServletRequest的实现类是HttpServletRequestWrapper,
 *              EncodeRequest就是对HttpServletRequestWrapper的一个装饰类, 
 *              装饰的方法是getParameter();
 *
 * @author linshuo
 *
 */
public class EncodeRequest extends HttpServletRequestWrapper {

    private HttpServletRequest req;

    public EncodeRequest(HttpServletRequest request) {
        super(request);
        this.req = request;
    }

    public String getParameter(String name) {

        String value = req.getParameter(name);
        try {
            value = new String(value.getBytes("iso-8859-1"), "utf-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return value;
    }

}
